/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasić                    *
 *   ivasic@gmail.com                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef EXCEPTIONLOGGER_H
#define EXCEPTIONLOGGER_H

#include <QObject>
#include <QList>
		
class Exception;
class ExLogObserver;
		
/**
 * @class ExceptionLogger
 * @brief Klasa za logovanje izuzetaka.
 * 
 * Svi izuzeci prosledjeni ExceptionManager-u sa parametrom za logovanje se dalje prosledjuju ovoj klasi.
 * ExceptionLogger ispisuje informacije o izuzetku na stderr ako je to dozvoljeno (m_stderrEnabled) i takodje
 * ispisuje iste informacije svim objektima koji su registrovani za to (ExLogObserver).
 * 
 * @see m_stderrEnabled
 * @see ExLogObserver
 * 
 * @author Ivan Vasić <ivasic@gmail.com>
*/

class ExceptionLogger : public QObject
{
		Q_OBJECT

	public:
		
		///Default konstruktor.
		ExceptionLogger(QObject *parent = 0);
		///Destruktor.
		~ExceptionLogger();
		
		/**
		 * @brief Registruje ExLogObserver objekat.
		 * 
		 * U svaki registrovani ExLogObserver će biti upisane informacije o izuzecima.
		 * Da bi izbacili neki ExLogObserver iz liste koristite ExceptionLogger::unregisterObserver()
		 * 
		 * @see ExLogObserver::write()
		 * @see ExceptionLogger::unregisterObserver()
		 * @see ExceptionLogger::logMessage()
		 */
		void registerObserver(ExLogObserver*);
		
		/**
		 * @brief Izbacuje ExLogObserver objekat iz liste observera.
		 *
		 * Da bi registrovali neki ExLogObserver iz liste koristite ExceptionLogger::registerObserver()
		 * 
		 * @see ExLogObserver::write()
		 * @see ExceptionLogger::registerObserver()
		 * @see ExceptionLogger::logMessage()
		 */
		void unregisterObserver(ExLogObserver*);
		
		
		/**
		 * @brief Ispisuje informacije o izuzetku u log.
		 * 
		 * Info o izuzetku se ispisuje na stderr ako je to dozvoljeno (m_stderrEnabled)
		 * i svi observeri dobiće istu kopiju informacije.
		 * 
		 * @see m_stderrEnabled
		 * @see ExLogObserver::write()
		 * @see ExceptionLogger::registerObserver()
		 * @see ExceptionLogger::unregisterObserver()
		 */
		void logMessage(Exception* ex);
		
		
		///Accessor za m_stderrEnabled.
		void setLogToStdErr(bool log);

		///Accessor za m_stderrEnabled.
		bool stderrEnabled() const { return m_stderrEnabled; }
	
		
	private:
		
		/**
		 * @brief Svi registrovani observeri.
		 * 
		 * Lista svih objekata koji treba da dobiju kopiju informacije o izuzetku koji se loguje.
		 * 
		 * @see ExLogObserver::write()
		 * @see ExceptionLogger::logMessage()
		 * @see ExceptionLogger::registerObserver()
		 * @see ExceptionLogger::unregisterObserver()
		 */
		QList<ExLogObserver*> m_observers;
		
		///Da li da ispisuje info na stderr
		bool m_stderrEnabled;
};

#endif
